IMEC seminar
June 10 2022 - Leuven, BE

Use the Space key to navigate through all slides and SHIFT + Space key to go back one slide.

NB: AbiPy can be interfaced with other packages (e.g ASE, phonopy) via converters.
Layered structure designed for different use-cases:
Closely connected to the ABINIT executable:
ABINIT and AbiPy communicate through binary netcdf files
Using conda and the conda forge channel (recommended):
conda install abipy --channel conda-forge
Since conda is not limited to python packages, one can install ABINIT in the same env with:
conda install abinit -c conda-forge
Using pip and python wheels:
pip install abipy --user
For further info see this installation howto
%embed https://abinit.github.io/abipy/index.html
%embed https://nbviewer.jupyter.org/github/abinit/abitutorials/blob/master/abitutorials/index.ipynb

abistruct.py --help for manpageabistruct.py COMMAND --help for help about COMMANDHTML documentation available at http://abinit.github.io/abipy/scripts/index.html

!abiopen.py si_scf_GSR.nc --print # or -p
================================= File Info =================================
Name: si_scf_GSR.nc
Directory: /Users/gmatteo/git_repos/abipy_imec_2022
Size: 14.83 kb
Access Time: Mon Jun 6 23:58:53 2022
Modification Time: Mon Jun 6 23:53:36 2022
Change Time: Mon Jun 6 23:53:36 2022
================================= Structure =================================
Full Formula (Si2)
Reduced Formula: Si
abc : 3.866975 3.866975 3.866975
angles: 60.000000 60.000000 60.000000
Sites (2)
# SP a b c cartesian_forces
--- ---- ---- ---- ---- -----------------------------------------------------------
0 Si 0 0 0 [-5.89948306e-27 -1.93366149e-27 2.91016904e-27] eV ang^-1
1 Si 0.25 0.25 0.25 [ 5.89948306e-27 1.93366149e-27 -2.91016904e-27] eV ang^-1
Abinit Spacegroup: spgid: 227, num_spatial_symmetries: 48, has_timerev: True, symmorphic: True
Stress tensor (Cartesian coordinates in GPa):
[[5.21161758e+00 7.86452261e-11 0.00000000e+00]
[7.86452261e-11 5.21161758e+00 0.00000000e+00]
[0.00000000e+00 0.00000000e+00 5.21161758e+00]]
Pressure: -5.212 (GPa)
Energy: -241.23647031 (eV)
============================== Electronic Bands ==============================
Number of electrons: 8.0, Fermi level: 5.598 (eV)
nsppol: 1, nkpt: 29, mband: 8, nspinor: 1, nspden: 1
smearing scheme: none (occopt 1), tsmear_eV: 0.272, tsmear Kelvin: 3157.7
Direct gap:
Energy: 2.532 (eV)
Initial state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000
Final state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 4, eig: 8.130, occ: 0.000
Fundamental gap:
Energy: 0.562 (eV)
Initial state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000
Final state: spin: 0, kpt: [+0.375, +0.375, +0.000], weight: 0.012, band: 4, eig: 6.161, occ: 0.000
Bandwidth: 11.856 (eV)
Valence maximum located at kpt index 0:
spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000
Conduction minimum located at kpt index 17:
spin: 0, kpt: [+0.375, +0.375, +0.000], weight: 0.012, band: 4, eig: 6.161, occ: 0.000
TIP: Use `--verbose` to print k-point coordinates with more digits
abiopen.py mgb2_kpath_FATBANDS.nc --expose --seaborn # or -e -sns

--expose with --notebook to generate notebook with predefined python code¶--panel option:¶abiopen.py out_DDB --panel # or -pn if you prefer the short option.


!abistruct.py convert si_scf_GSR.nc -f cif
# generated using pymatgen data_Si _symmetry_space_group_name_H-M 'P 1' _cell_length_a 3.86697464 _cell_length_b 3.86697464 _cell_length_c 3.86697464 _cell_angle_alpha 60.00000000 _cell_angle_beta 60.00000000 _cell_angle_gamma 60.00000000 _symmetry_Int_Tables_number 1 _chemical_formula_structural Si _chemical_formula_sum Si2 _cell_volume 40.88829233 _cell_formula_units_Z 2 loop_ _symmetry_equiv_pos_site_id _symmetry_equiv_pos_as_xyz 1 'x, y, z' loop_ _atom_site_type_symbol _atom_site_label _atom_site_symmetry_multiplicity _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy Si Si0 1 0.00000000 0.00000000 0.00000000 1 Si Si1 1 0.25000000 0.25000000 0.25000000 1

abiview.py ddb ZnSe_hex_qpt_DDB --seaborn

--phononwebsite to visualize data on the phononwebsite by H. Miranda¶
!abicomp.py structure *.cif si_nscf_GSR.nc *_DDB
Spglib options: symprec= 0.001 angle_tolerance= 5.0
Lattice parameters:
formula natom alpha beta gamma a b \
AlAs.cif Al1 As1 2 60.0 60.0 60.0 3.970101 3.970101
si.cif Si2 2 60.0 60.0 60.0 3.866975 3.866975
si_nscf_GSR.nc Si2 2 60.0 60.0 60.0 3.866975 3.866975
ZnSe_hex_qpt_DDB Zn2 Se2 4 90.0 90.0 120.0 4.050187 4.050187
alas_DDB Al1 As1 2 60.0 60.0 60.0 3.970101 3.970101
elastic_DDB Al2 As2 4 90.0 90.0 120.0 3.989448 3.989448
c volume abispg_num spglib_symb spglib_num \
AlAs.cif 3.970101 44.247584 None F-43m 216
si.cif 3.866975 40.888292 None Fd-3m 227
si_nscf_GSR.nc 3.866975 40.888292 227 Fd-3m 227
ZnSe_hex_qpt_DDB 6.652328 94.504936 0 P6_3mc 186
alas_DDB 3.970101 44.247584 0 F-43m 216
elastic_DDB 6.497130 89.552529 0 P6_3mc 186
spglib_lattice_type
AlAs.cif cubic
si.cif cubic
si_nscf_GSR.nc cubic
ZnSe_hex_qpt_DDB hexagonal
alas_DDB cubic
elastic_DDB hexagonal

Main entry point:
from abipy import abilab
abifile = abilab.abiopen("filename.nc")
where filename.nc is a netcdf file (support also text files e.g. run.abo, run.log, out_DDB)
abifile is the AbiFile subclass associated to the given file extension:
abiopen.py --help) gsr = abiopen("si_nscf_GSR.nc")
gsr.ebands.plot(with_gaps=True);
gsr.ebands.plotly(with_gaps=True); # obj.plot becomes obj.plotly
gsr.ebands.plotly(with_gaps=True, chart_studio=True);

gsr.ebands.kpoints.plotly(title="k-path in 3d with plotly");
znse_ddb = abilab.abiopen("ZnSe_hex_qpt_DDB")
phbst_file, phdos_file = znse_ddb.anaget_phbst_and_phdos_files() # call anaddb
phbst_file.phbands.plotly_with_phdos(phdos_file.phdos, units="cm-1");
paths = [
"mgb2_888k_0.01tsmear_DDB",
"mgb2_888k_0.04tsmear_DDB",
"mgb2_121212k_0.01tsmear_DDB",
"mgb2_121212k_0.04tsmear_DDB",
]
paths = [os.path.join(abidata.dirpath, "refs", "mgb2_phonons_nkpt_tsmear", f)
for f in paths]
robot = abilab.DdbRobot()
for path in paths:
robot.add_file(path, path)
# Define function to change labels:
func = lambda ddb: "nkpt: %s, tsmear: %.2f" % (
ddb.header["nkpt"], ddb.header["tsmear"])
robot.remap_labels(func)
robot
robot.get_params_dataframe()
| nkpt | nsppol | ecut | tsmear | occopt | ixc | nband | usepaw | |
|---|---|---|---|---|---|---|---|---|
| nkpt: 256, tsmear: 0.01 | 256 | 1 | 35.0 | 0.01 | 4 | 1 | 8 | 0 |
| nkpt: 256, tsmear: 0.04 | 256 | 1 | 35.0 | 0.04 | 4 | 1 | 8 | 0 |
| nkpt: 864, tsmear: 0.01 | 864 | 1 | 35.0 | 0.01 | 4 | 1 | 8 | 0 |
| nkpt: 864, tsmear: 0.04 | 864 | 1 | 35.0 | 0.04 | 4 | 1 | 8 | 0 |
robot.get_lattice_dataframe()
| formula | natom | alpha | beta | gamma | a | b | c | volume | abispg_num | spglib_symb | spglib_num | spglib_lattice_type | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| nkpt: 256, tsmear: 0.01 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
| nkpt: 256, tsmear: 0.04 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
| nkpt: 864, tsmear: 0.01 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
| nkpt: 864, tsmear: 0.04 | Mg1 B2 | 3 | 90.0 | 90.0 | 120.0 | 3.086 | 3.086 | 3.523 | 29.055953 | 0 | P6/mmm | 191 | hexagonal |
# Invoke anaddb and store results
r = robot.anaget_phonon_plotters(nqsmall=2)
r.phbands_plotter.gridplot_with_hue("tsmear", with_dos=True);
%embed https://abinit.github.io/abipy/gallery/index.html

Here, we mainly discuss the abipy.flowtk API.
scheduler.yml providing:
manager.yml providing:
See this page for examples or use the abidoc.py script and the syntax:
def make_scf_input(ecut=2, ngkpt=(4, 4, 4)):
"""
Generate an `AbinitInput` to perform GS calculation for AlAs.
Args:
ecut: Cutoff energy in Ha.
ngkpt: k-mesh divisions
Return:
`AbinitInput` object
"""
gs_inp = abilab.AbinitInput(structure="AlAs.cif",
pseudos=["13al.pspnc", "33as.pspnc"])
# Set the value of the Abinit variables needed for GS runs.
gs_inp.set_vars(
nband=4,
ecut=ecut,
ngkpt=ngkpt,
nshiftk=4,
shiftk=[0.0, 0.0, 0.5, # This gives the usual fcc Monkhorst-Pack grid
0.0, 0.5, 0.0,
0.5, 0.0, 0.0,
0.5, 0.5, 0.5],
tolvrs=1.0e-10,
)
return gs_inp
make_scf_input()
AbiniInput one can easily build more complicate workflows:¶def build_flow_alas_phonons():
"""
Build and return a Flow to compute the dynamical matrix on a (2, 2, 2) qmesh
as well as DDK and Born effective charges.
The final DDB with all perturbations will be merged automatically and placed
in the Flow `outdir` directory.
"""
from abipy import flowtk
scf_input = make_scf_input(ecut=6, ngkpt=(4, 4, 4))
return flowtk.PhononFlow.from_scf_input("flow_alas_phonons", scf_input,
ph_ngqpt=(2, 2, 2), with_becs=True)
flow_phbands = build_flow_alas_phonons()
flow_phbands.get_graphviz()
The simplest way to start the scheduler from the shell is via e.g.:
run_elastic.py --scheduler # -s for the short option
See scripts available in the Flow Gallery
For non-trivial Flows, use nohup
so that we can disconnect from the shell session without killing the scheduler.
nohup run_elastic.py -s > log 2> err &
Obviously, it is possible to submit a Slurm script that executes the script with one core to avoid runnning on the frontend.
To interact with the Flow, use the abirun.py script, e.g:
abirun.py FLOWDIR status

scf_input = make_scf_input() # Build input for GS calculation
elast_work = flowtk.ElasticWork.from_scf_input(scf_input,
with_relaxed_ion=True,
with_piezo=True)

Compute $\epsilon^{\alpha\beta}_{n\bf{k}}$ and the effective mass tensor at the band edges using $|u_{n\mathbf{k}}\rangle$, and the k-derivatives $|u_{n\mathbf{k}}^\alpha\rangle$ $H^\alpha_{\mathbf{k}}$, $H^{\alpha\beta}_{\mathbf{k}}$
For the formalism, see J. Laflamme Janssen, et. al. Phys. Rev. B 93, 205147
flow = flowtk.Flow("flow_effmass_dfpt")
# Build input for GS SCF calculation.
scf_input = make_scf_input()
# This object implements all the worflow logic
from abipy.flowtk.effmass_works import EffMassAutoDFPTWork
work = EffMassAutoDFPTWork.from_scf_input(scf_input)
flow.register_work(work)


NB: This is a simplified version with just 2 q-points in the path. In our work, we used 278 points.
%embed https://abinit.github.io/abipy/flow_gallery/index.html